package nbcp.myoql

import nbcp.base.utils.FileUtil
import nbcp.myoql.code.generator.db.mongo.MorGenerator4Kotlin
import nbcp.myoql.code.generator.db.mysql.DbrGenerator4Kotlin
import org.junit.jupiter.api.Test
import java.io.File
import java.io.FileWriter


class tool : TestBase() {

    @Test
    fun gen_dbr() {
        var path = System.getProperty("user.dir");

        var list = DbrGenerator4Kotlin()
            .generateEntity(
                "nbcp.myoql.db.sql.entity.",
                "nbcp.myoql.db.sql.table",
                ignoreGroups = listOf()
            )

        var targetEntityPathName = FileUtil.resolvePath(
            File(path).parentFile.path + "/ktmyoql/kotlin",
            "nbcp.myoql.db.sql.table".split(".").joinToString("/")
        )

        File(targetEntityPathName).deleteRecursively();
        File(targetEntityPathName).mkdirs()


        list.forEach {
            writeToFile(FileUtil.resolvePath(targetEntityPathName, it.code), it.value);
        }
    }

    fun writeToFile(fileName: String, content: String) {
        FileWriter(fileName, true).use { moer_File ->
            moer_File.appendLine(content)
            moer_File.flush()
        }
    }

    @Test
    fun gen_mor() {
        val path = System.getProperty("user.dir")

        var list = MorGenerator4Kotlin()
            .generateEntity(
                "nbcp.myoql.db.mongo.entity.",
                "nbcp.myoql.db.mongo.table",
                ignoreGroups = listOf()
            )

        var targetEntityPathName = FileUtil.resolvePath(
            File(path).parentFile.path + "/ktmyoql/kotlin",
            "nbcp.myoql.db.mongo.table.".split(".").joinToString("/")
        )
        File(targetEntityPathName).deleteRecursively();
        File(targetEntityPathName).mkdirs()


        list.forEach {
            writeToFile(FileUtil.resolvePath(targetEntityPathName, it.code), it.value);
        }
    }


}